]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
location: Separate setting for enabling/disabling
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 6 Aug 2014 16:04:00 +0000 (17:04 +0100)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Sat, 9 Aug 2014 14:59:41 +0000 (15:59 +0100)
Having the on/off setting be backed by a boolean in dconf makes sense
anyway but this is mainly to be able to remember the max accuracy set
before user disabled geolocation so that when they enable it next time,
we have the max accuracy level on same value as before.

There hasn't been a real need for this but now we are about to add
geolocation settings in control center and it'll be easiser for
control-center to simply toggle a boolean property rather than to have
to know about and deal with accuracy levels.

Later we might also want to add accuracy level settings to privacy panel
so keeping the accuracy level setting around still. However we no longer
support 'off' accuracy level as the new boolean property covers that.

This also implies that we no longer track available accuracy level,
which made the code a bit hard to follow/maintain.

https://bugzilla.gnome.org/show_bug.cgi?id=734483

data/org.gnome.shell.gschema.xml.in.in
js/ui/status/location.js

index 51900da588f09398390520b6c8204680b0955e6f..f60772e5cf53d41e4eb83b7c63b6df25140bd7f4 100644 (file)
   </schema>
 
   <enum id="org.gnome.shell.geoclue.AccuracyLevel">
-    <value value="0" nick="off"/>
     <value value="1" nick="country"/>
     <value value="4" nick="city"/>
     <value value="5" nick="neighborhood"/>
   <schema id="org.gnome.shell.location"
           path="/org/gnome/shell/location/"
           gettext-domain="@GETTEXT_PACKAGE@">
+    <key type="b" name="enabled">
+      <default>true</default>
+      <_summary>Geolocation services are enabled.</_summary>
+      <_description>
+       If true, applications are allowed to access location information.
+      </_description>
+    </key>
     <key name="max-accuracy-level" enum="org.gnome.shell.geoclue.AccuracyLevel">
       <default>'exact'</default>
       <_summary>The maximum accuracy level of location.</_summary>
       <_description>
         Configures the maximum level of location accuracy applications are
-        allowed to see. Valid options are 'off' (disable location tracking),
-        'country', 'city', 'neighborhood', 'street', and 'exact' (typically
-        requires GPS receiver). Please keep in mind that this only controls
-        what GeoClue will allow applications to see and they can find user's
-        location on their own using network resources (albeit with street-level
-        accuracy at best).
+        allowed to see. Valid options are 'country', 'city', 'neighborhood',
+        'street', and 'exact' (typically requires GPS receiver). Please keep in
+        mind that this only controls what GeoClue will allow applications to see
+        and they can find user's location on their own using network resources
+        (albeit with street-level accuracy at best).
       </_description>
     </key>
   </schema>
index 15b5f80cbda24f5d94fc0c42edcbdff1b05e2dc3..7444ee76769e851fc6d7cf082ada7b328e5b3c55 100644 (file)
@@ -11,6 +11,7 @@ const Shell = imports.gi.Shell;
 
 const LOCATION_SCHEMA = 'org.gnome.shell.location';
 const MAX_ACCURACY_LEVEL = 'max-accuracy-level';
+const ENABLED = 'enabled';
 
 var GeoclueIface = '<node> \
   <interface name="org.freedesktop.GeoClue2.Manager"> \
@@ -44,6 +45,8 @@ const Indicator = new Lang.Class({
         this.parent();
 
         this._settings = new Gio.Settings({ schema_id: LOCATION_SCHEMA });
+        this._settings.connect('changed::' + ENABLED,
+                               Lang.bind(this, this._onMaxAccuracyLevelChanged));
         this._settings.connect('changed::' + MAX_ACCURACY_LEVEL,
                                Lang.bind(this, this._onMaxAccuracyLevelChanged));
 
@@ -123,7 +126,6 @@ const Indicator = new Lang.Class({
         this._propertiesChangedId = this._proxy.connect('g-properties-changed',
                                                         Lang.bind(this, this._onGeocluePropsChanged));
 
-        this._availableAccuracyLevel = this._proxy.AvailableAccuracyLevel;
         this._syncIndicator();
 
         this._proxy.AddAgentRemote('gnome-shell', Lang.bind(this, this._onAgentRegistered));
@@ -148,10 +150,8 @@ const Indicator = new Lang.Class({
     },
 
     _onOnOffAction: function() {
-        if (this._getMaxAccuracyLevel() == 0)
-            this._settings.set_enum(MAX_ACCURACY_LEVEL, this._availableAccuracyLevel);
-        else
-            this._settings.set_enum(MAX_ACCURACY_LEVEL, 0);
+        let enabled = this._settings.get_boolean(ENABLED);
+        this._settings.set_boolean(ENABLED, !enabled);
     },
 
     _onSessionUpdated: function() {
@@ -160,12 +160,12 @@ const Indicator = new Lang.Class({
     },
 
     _updateMenuLabels: function() {
-        if (this._getMaxAccuracyLevel() == 0) {
-            this._item.status.text = _("Disabled");
-            this._onOffAction.label.text = _("Enable");
-        } else {
+        if (this._settings.get_boolean(ENABLED)) {
             this._item.status.text = this._indicator.visible ? _("In Use") : _("Enabled");
             this._onOffAction.label.text = _("Disable");
+        } else {
+            this._item.status.text = _("Disabled");
+            this._onOffAction.label.text = _("Enable");
         }
     },
 
@@ -179,7 +179,10 @@ const Indicator = new Lang.Class({
     },
 
     _getMaxAccuracyLevel: function() {
-        return this._settings.get_enum(MAX_ACCURACY_LEVEL);
+        if (this._settings.get_boolean(ENABLED))
+            return this._settings.get_enum(MAX_ACCURACY_LEVEL);
+        else
+            return 0;
     },
 
     _notifyMaxAccuracyLevel: function() {
@@ -191,12 +194,6 @@ const Indicator = new Lang.Class({
         let unpacked = properties.deep_unpack();
         if ("InUse" in unpacked)
             this._syncIndicator();
-        if ("AvailableAccuracyLevel" in unpacked) {
-            this._availableAccuracyLevel = this._proxy.AvailableAccuracyLevel;
-
-            if (this._getMaxAccuracyLevel() != 0)
-                this._settings.set_enum(MAX_ACCURACY_LEVEL, this._availableAccuracyLevel);
-        }
     }
 });